package com.hmdp.utils;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//第二层拦截器
public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //1、获取ThreadLocal的用户信息判断有无此用户信息
        if (UserHolder.getUser() == null)
        {
            //没有用户则拦截返回401
            response.setStatus(401);
            return false;
        }
        //8有用户则放行
        return true;
    }

}
